using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace ICP_MS.Plugin.iMass;

public class FormLogin : Form
{
	private IContainer components = null;

	private Label label1;

	private Label label2;

	private TextBox txtUser;

	private TextBox txtPSW;

	private GroupBox groupBox1;

	private Button button1;

	private Button button2;

	private ErrorProvider loginError;

	public FormLogin()
	{
		InitializeComponent();
	}

	private void FormLogin_Load(object sender, EventArgs e)
	{
		txtUser.Text = "User";
		Text = Lang.Txt("AddiMass.Text16");
		groupBox1.Text = Lang.Txt("AddiMass.Text17");
		label1.Text = Lang.Txt("AddiMass.Text18");
		label2.Text = Lang.Txt("AddiMass.Text19");
		button2.Text = Lang.Txt("AddiMass.Text14");
		button1.Text = Lang.Txt("AddiMass.Text15");
	}

	protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
	{
		switch (keyData)
		{
		case Keys.Return:
			button2.PerformClick();
			break;
		case Keys.Escape:
			button1.PerformClick();
			break;
		}
		return base.ProcessCmdKey(ref msg, keyData);
	}

	private void button2_Click(object sender, EventArgs e)
	{
		loginError.Clear();
		string name = txtUser.Text;
		name.Trim();
		string psw = txtPSW.Text;
		psw.Trim();
		if (UserManager.Instance.GetUserInfo(name, psw))
		{
			UserManager.Instance.OnUserChanged();
			base.DialogResult = DialogResult.OK;
		}
		else
		{
			loginError.SetError(txtPSW, "密码或者用户名错误");
		}
	}

	private void button1_Click(object sender, EventArgs e)
	{
		base.DialogResult = DialogResult.Cancel;
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.components = new System.ComponentModel.Container();
		this.label1 = new System.Windows.Forms.Label();
		this.label2 = new System.Windows.Forms.Label();
		this.txtUser = new System.Windows.Forms.TextBox();
		this.txtPSW = new System.Windows.Forms.TextBox();
		this.groupBox1 = new System.Windows.Forms.GroupBox();
		this.button1 = new System.Windows.Forms.Button();
		this.button2 = new System.Windows.Forms.Button();
		this.loginError = new System.Windows.Forms.ErrorProvider(this.components);
		this.groupBox1.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.loginError).BeginInit();
		base.SuspendLayout();
		this.label1.AutoSize = true;
		this.label1.Location = new System.Drawing.Point(66, 27);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(41, 12);
		this.label1.TabIndex = 0;
		this.label1.Text = "用户：";
		this.label2.AutoSize = true;
		this.label2.Location = new System.Drawing.Point(66, 66);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(41, 12);
		this.label2.TabIndex = 0;
		this.label2.Text = "密码：";
		this.txtUser.Location = new System.Drawing.Point(125, 24);
		this.txtUser.Name = "txtUser";
		this.txtUser.Size = new System.Drawing.Size(85, 21);
		this.txtUser.TabIndex = 1;
		this.txtPSW.Location = new System.Drawing.Point(125, 63);
		this.txtPSW.Name = "txtPSW";
		this.txtPSW.Size = new System.Drawing.Size(85, 21);
		this.txtPSW.TabIndex = 2;
		this.txtPSW.UseSystemPasswordChar = true;
		this.groupBox1.Controls.Add(this.txtPSW);
		this.groupBox1.Controls.Add(this.txtUser);
		this.groupBox1.Controls.Add(this.label2);
		this.groupBox1.Controls.Add(this.label1);
		this.groupBox1.Location = new System.Drawing.Point(6, 6);
		this.groupBox1.Name = "groupBox1";
		this.groupBox1.Size = new System.Drawing.Size(266, 106);
		this.groupBox1.TabIndex = 2;
		this.groupBox1.TabStop = false;
		this.groupBox1.Text = "登录";
		this.button1.Location = new System.Drawing.Point(157, 125);
		this.button1.Name = "button1";
		this.button1.Size = new System.Drawing.Size(59, 27);
		this.button1.TabIndex = 4;
		this.button1.Text = "取消";
		this.button1.UseVisualStyleBackColor = true;
		this.button1.Click += new System.EventHandler(button1_Click);
		this.button2.Location = new System.Drawing.Point(74, 125);
		this.button2.Name = "button2";
		this.button2.Size = new System.Drawing.Size(59, 27);
		this.button2.TabIndex = 3;
		this.button2.Text = "确定";
		this.button2.UseVisualStyleBackColor = true;
		this.button2.Click += new System.EventHandler(button2_Click);
		this.loginError.ContainerControl = this;
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(284, 164);
		base.Controls.Add(this.button2);
		base.Controls.Add(this.button1);
		base.Controls.Add(this.groupBox1);
		base.Name = "FormLogin";
		base.ShowIcon = false;
		base.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
		this.Text = "用户登录";
		base.Load += new System.EventHandler(FormLogin_Load);
		this.groupBox1.ResumeLayout(false);
		this.groupBox1.PerformLayout();
		((System.ComponentModel.ISupportInitialize)this.loginError).EndInit();
		base.ResumeLayout(false);
	}
}
